package com.ect.ui.test;

import java.awt.EventQueue;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * 
 * @author zhouxiaochen 2011-11-13
 * 
 */
public class LoginDialog01 {

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				LoginFrame loginFrame = new LoginFrame();
				loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				loginFrame.setVisible(true);
			}
		});
	}
}

class LoginFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 300;
	private static final int DEFAULT_HEIGHT = 200;

	public LoginFrame() {
		// set frame size
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		setTitle("Login");
		// add something when close the window
		addWindowListener(new Terminator());
		// add a panel to frame
		LoginPanel loginPanel = new LoginPanel();
		add(loginPanel);
	}
}

class LoginPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 300;
	private static final int DEFAULT_HEIGHT = 200;

	public LoginPanel() {
		// set panel size
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		// add a text field to login panel
		JTextField textName = new JTextField("Name");
		textName.setSize(200, 30);

		add(textName);
	}
}

class Terminator implements WindowListener {
	@Override
	public void windowActivated(WindowEvent arg0) {
	}

	@Override
	public void windowClosed(WindowEvent arg0) {
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		System.out.println("ok exit!!!");
		System.exit(0);
	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {
	}

	@Override
	public void windowIconified(WindowEvent arg0) {
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
	}
}
